﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using h = functionService.shorts;
namespace ETALON
{
    public partial class FormDATEspo : Form
    {
        public DateTime dateSelectS, dateSetS, dateIncomingS; public bool bOks = false, bOkp = false ;
        public DateTime dateSelectP, dateSetP, dateIncomingP; 
        public FormDATEspo()
        {
            InitializeComponent(); dateSelectS = new DateTime(); dateSelectP = new DateTime();
        }
        public FormDATEspo(object  dts, object  dtp)
            : this()
        {
             //DateTime dts, DateTime dtp
           //h.m( h.aa(dts, dtp) );


            dateIncomingS = Convert.ToDateTime(dts); monthCalendar1.SelectionStart = dateIncomingS;
            monthCalendar1.SelectionEnd = dateIncomingS;
            dateIncomingP = Convert.ToDateTime(dtp); monthCalendar2.SelectionStart = dateIncomingP; 
            monthCalendar2.SelectionEnd = dateIncomingP; 
        }
        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            dateSetS = e.Start; bOks = true;
        }

        private void monthCalendar2_DateSelected(object sender, DateRangeEventArgs e)
        {
            dateSetP = e.Start; bOkp = true;
            this.Close();
        }

        private void FormDATEspo_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (bOks == true && bOkp == true)
            {
                if (dateSetS <= dateSetP) { dateSelectS = dateSetS; dateSelectP = dateSetP; }
                else
                { 
                    bOks = false; bOkp = false; 
                    MessageBox.Show(
                   string.Concat( "Неправильно указан период! НАЧАЛЬНАЯ дата: ", dateSetS.ToShortDateString()
                   , " КОНЕЧНАЯ дата: ", dateSetP.ToShortDateString()));
                    dateSelectS = dateIncomingS; dateSelectP = dateIncomingP;
                }
            }
            else if (bOks == false && bOkp == true)
            {
                if (dateSetS <= dateSetP) { dateSelectS = dateSetS; dateSelectP = dateSetP; bOks = true; }
                else
                {
                    bOks = false; bOkp = false;
                    MessageBox.Show(
                   string.Concat("Неправильно указан период! НАЧАЛЬНАЯ дата: ", dateSetS.ToShortDateString()
                   , " КОНЕЧНАЯ дата: ", dateSetP.ToShortDateString()));
                    dateSelectS = dateIncomingS; dateSelectP = dateIncomingP;
                }
            }
            else { dateSelectS = dateIncomingS; dateSelectP = dateIncomingP; }
        }
    }
}
